﻿using System.Collections.Generic;
using System.Linq;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class AdminProjectDao
    {
        private MyDbContext DbContext = new MyDbContext();

        public List<Project> getProjectList(string role)
        {
            if (role == "school")
            {
                return DbContext.Project.Where(p => p.category_id == 1 || p.category_id == 3).ToList();
            }
            if (role == "bureau")
            {
                return DbContext.Project.Where(p => p.category_id == 2 || p.category_id == 4).ToList();
            }

            return null;
        }

        public void addProject(Project project)
        {
            DbContext.Project.Add(project);
            DbContext.SaveChanges();
        }

        public Project getProjectById(int product_id)
        {
            return DbContext.Project.Where(p => p.product_id == product_id).ToList().First();
        }

        public void updateProject(Project project)
        {
            Project toProject = DbContext.Project.Where(p => p.product_id == project.product_id).ToList().First();
            toProject.product_intro = project.product_intro;
            toProject.product_notice = project.product_notice;
            toProject.product_picture = project.product_picture;
            toProject.product_price = project.product_price;
            toProject.product_title = project.product_title;
            DbContext.Update(toProject);
            DbContext.SaveChanges();
        }
    }
}